# -*- encoding: utf-8 -*-
from shapely.wkt import loads as wkt_loads
import dsl
from . import FixtureTest


class NormalizePoiKind(FixtureTest):
    def test_aeroway_gate(self):
        # Node: Gate G102 (1096088604)
        self.generate_fixtures(dsl.way(1096088604, wkt_loads('POINT (-122.392940381859 37.618783212573)'), {u'source': u'openstreetmap.org', u'layer': u'1', u'aeroway': u'gate', u'ref': u'G102', u'name': u'Gate G102'}))  # noqa

        self.assert_has_feature(
            16, 10487, 25366, 'pois',
            {'id': 1096088604, 'kind': 'aeroway_gate'})

    def test_gate_not_aeroway(self):
        # TODO: not sure what this is testing? the node seems to have been
        # updated recently to remove the aeroway=gate tag.
        # Node: Gate 1 (2618197593)
        self.generate_fixtures(dsl.way(2618197593, wkt_loads('POINT (-123.370931201114 48.423999970984)'), {u'access': u'customers', u'source': u'openstreetmap.org', u'barrier': u'gate'}),dsl.way(320595943, wkt_loads('LINESTRING (-123.370904071992 48.42390256265609, -123.37094916742 48.4239960961153, -123.370931201114 48.423999970984)'), {u'access': u'permissive', u'bridge': u'yes', u'surface': u'metal', u'highway': u'footway', u'source': u'openstreetmap.org'}))  # noqa

        self.assert_has_feature(
            16, 10309, 22665, 'pois',
            {'id': 2618197593, 'kind': 'gate', 'aeroway': type(None)})

    def test_ski_rental(self):
        # Node: Lone Star Sports
        self.generate_fixtures(dsl.way(2122898936, wkt_loads('POINT (-106.047818363838 39.48099811213307)'), {u'addr:housenumber': u'110', u'amenity': u'ski_rental', u'contact:fax': u'+1 970 453 7323', u'name': u'Lone Star Sports', u'contact:email': u'info@skilonestar.com', u'addr:postcode': u'80424', u'contact:website': u'http://skilonestar.com/', u'contact:phone': u'+1 970 453 2003', u'addr:city': u'Breckenridge', u'source': u'openstreetmap.org', u'rental': u'ski', u'addr:street': u'South Park Avenue'}))  # noqa

        self.assert_has_feature(
            16, 13462, 24933, 'pois',
            {'id': 2122898936, 'kind': 'ski_rental'})

    def test_wood(self):
        self.generate_fixtures(dsl.way(52497271, wkt_loads('POLYGON ((-121.954353215747 37.34413271456221, -121.954112646914 37.34428461761629, -121.953889595229 37.34453921701549, -121.953810004495 37.3445377886903, -121.953726910331 37.3444308784707, -121.953744607142 37.34433389498678, -121.954353215747 37.34413271456221))'), {u'way_area': u'1191.25', u'source': u'openstreetmap.org', u'landuse': u'wood', u'natural': u'wood'}))  # noqa

        self.assert_has_feature(
            16, 10566, 25429, 'landuse',
            {'id': 52497271, 'kind': 'wood'})

        self.generate_fixtures(dsl.way(207859675, wkt_loads('POLYGON ((-117.89005453116 33.91136551127548, -117.890027671533 33.91175720307361, -117.889979432002 33.9118240007339, -117.889933797586 33.91180841958788, -117.889847469487 33.91179552227351, -117.889797074 33.91180402108199, -117.889737964854 33.91183958187699, -117.889576627429 33.91175772493049, -117.889617321111 33.91172156769318, -117.889649480799 33.9116391887757, -117.889606631159 33.91161481056499, -117.889652175744 33.91149455953338, -117.889550306791 33.91082009198559, -117.88888258904 33.91056646635377, -117.889542221954 33.91055297243508, -117.889633400955 33.9104550109947, -117.889421488379 33.91019899860129, -117.889343784107 33.91020347174229, -117.889270840906 33.9101460664147, -117.889118486634 33.90998756786778, -117.889356630016 33.90954725944538, -117.889737515696 33.90960742363259, -117.889998566118 33.90958871086019, -117.889974131942 33.9113676732641, -117.89005453116 33.91136551127548))'), {u'way_area': u'18306.8', u'source': u'openstreetmap.org', u'landuse': u'wood'}))  # noqa

        self.assert_has_feature(
            16, 11306, 26199, 'landuse',
            {'id': 207859675, 'kind': 'wood'})

    def test_natural_wood(self):
        self.generate_fixtures(dsl.way(417405367, wkt_loads('POLYGON ((-122.429971183658 37.80650021176, -122.429855929807 37.80668041601299, -122.429735196233 37.80680746010199, -122.42969504154 37.8069792176848, -122.429756665968 37.8070342935854, -122.429807600445 37.8071380576062, -122.429711121384 37.80719959201478, -122.429603772707 37.80724622186117, -122.429472259349 37.80730548501768, -122.429317479626 37.80726666233261, -122.429234205799 37.80726027468589, -122.429142218314 37.8072518997705, -122.429041068013 37.80721137368349, -122.428970190937 37.80717680938509, -122.428924197195 37.8070416748886, -122.428882335702 37.80688808685169, -122.428817926497 37.80684138580488, -122.42877229208 37.80670788310549, -122.428847391238 37.8065213621835, -122.428823316388 37.806411209576, -122.428847391238 37.80631376128829, -122.428855386244 37.80622050038839, -122.428898415546 37.80614626065339, -122.428953122947 37.80607216279369, -122.429131887688 37.80605278661688, -122.42936473101 37.8060818153926, -122.429389165186 37.8061652109561, -122.429413329867 37.80623299196168, -122.429450879446 37.80629772098968, -122.429432104656 37.80635826245238, -122.429399944969 37.806411209576, -122.429290979325 37.80648119056859, -122.42936769545 37.8065107869725, -122.429464264343 37.80648537807008, -122.42957161302 37.8064706153519, -122.429630632334 37.80654897128419, -122.429703665367 37.80658332295299, -122.429749299783 37.80648786218111, -122.429799785102 37.8064073769437, -122.429888089495 37.80634335775919, -122.429936418857 37.8063730961678, -122.429971183658 37.80650021176))'), {u'source': u'openstreetmap.org', u'way_area': u'14758.6', u'natural': u'wood'}))  # noqa

        self.assert_has_feature(
            16, 10480, 25323, 'landuse',
            {'id': 417405367, 'kind': 'natural_wood'})

    def test_forest(self):
        self.generate_fixtures(dsl.way(422270533, wkt_loads('POLYGON ((-122.450519157636 37.8047972988937, -122.450366174543 37.80501349215022, -122.450113208959 37.80504365695018, -122.449879287659 37.80533657426129, -122.449729269006 37.80561898604738, -122.449439472496 37.8055701549336, -122.448976121472 37.80544459920371, -122.448833469005 37.80589791897051, -122.448565681219 37.80598848322479, -122.448440725563 37.80517269117898, -122.449436508055 37.8049494717574, -122.450519157636 37.8047972988937))'), {u'way_area': u'15894.9', u'source': u'openstreetmap.org', u'landuse': u'forest'}))  # noqa

        self.assert_has_feature(
            16, 10476, 25324, 'landuse',
            {'id': 422270533, 'kind': 'forest'})

    def test_natural_forest(self):
        self.generate_fixtures(dsl.way(95360670, wkt_loads('POLYGON ((-82.3274026380452 28.12952385108719, -82.3273248439416 28.12961606428148, -82.32722558010271 28.12970368258679, -82.3270217523647 28.12980302549719, -82.3268769439409 28.12993548256789, -82.32678298016221 28.1301577755853, -82.32660601205119 28.1304155588564, -82.3265416028454 28.13054809439029, -82.32656576752649 28.13063555349319, -82.3266461667445 28.13073497475989, -82.3264959684289 28.1308058767225, -82.3263646347344 28.1306899777359, -82.3263163053721 28.13058120844311, -82.32610978268829 28.1304984232919, -82.32601860368699 28.13026432713549, -82.32609639779059 28.130108104306, -82.32633508016148 28.1297722878282, -82.3265228280559 28.12966819163628, -82.32671596584198 28.12957122522958, -82.32683130952449 28.12924475517119, -82.3267776801021 28.12902951096099, -82.32676959526449 28.12874566046377, -82.3267589053126 28.1285754131819, -82.32664895152179 28.1282819756315, -82.32653890789949 28.12817795721401, -82.32658184737009 28.12811172761308, -82.32660331710538 28.1279982023766, -82.32668111120898 28.12801475979818, -82.32669719105259 28.12813541499899, -82.32685277925978 28.12820639790329, -82.3268714642177 28.12827017156629, -82.3268553843741 28.12838139908158, -82.32692787841749 28.12843107116109, -82.3271423961074 28.12861320192259, -82.32724174977778 28.12885451084099, -82.32724174977778 28.12902008361909, -82.32724974478378 28.12914541174328, -82.3273946430392 28.1293795895648, -82.3274026380452 28.12952385108719))'), {u'source': u'openstreetmap.org', u'way_area': u'18311.3', u'natural': u'forest'}))  # noqa

        self.assert_has_feature(
            16, 17780, 27428, 'landuse',
            {'id': 95360670, 'kind': 'natural_forest'})

    def test_park(self):
        # Way: Stables & Equestrian Area (393312618)
        self.generate_fixtures(dsl.way(393312618, wkt_loads('POLYGON ((-123.453662715015 38.71466306523849, -123.453623728132 38.7146888594137, -123.453439214172 38.71481061059857, -123.452986463269 38.71510941530448, -123.452278411162 38.71497539842917, -123.45159182879 38.71442285653529, -123.4511733037 38.71410477326951, -123.451066044855 38.71379495964889, -123.451248402857 38.71360248200389, -123.451505860018 38.71346860249141, -123.451066044855 38.71296630675548, -123.451325657972 38.71279878059959, -123.451546194374 38.71265669848519, -123.452261163509 38.71333458253979, -123.453662715015 38.71466306523849))'), {u'way_area': u'48331.1', u'source': u'openstreetmap.org', u'landuse': u'park', u'name': u'Stables & Equestrian Area'}))  # noqa

        self.assert_has_feature(
            16, 10294, 25113, 'landuse',
            {'id': 393312618, 'kind': 'park'})

    def test_natural_park(self):
        self.generate_fixtures(dsl.way(469494860, wkt_loads('POLYGON ((-83.25251817051958 42.48312607658509, -83.25211303032648 42.48363506266588, -83.2518422780998 42.48330355638759, -83.25188467858131 42.4832787794689, -83.25245097653639 42.48303220221938, -83.25248457352799 42.4830373696193, -83.2525164637206 42.48305426303919, -83.25251817051958 42.48312607658509))'), {u'source': u'openstreetmap.org', u'way_area': u'2992.13', u'natural': u'park', u'name': u'Nature Walk - Towne Square Buildings'}))  # noqa

        self.assert_has_feature(
            16, 17612, 24209, 'landuse',
            {'id': 469494860, 'kind': 'natural_park'})
